package pers.lan.stack;

import java.util.Stack;

/**
 * @author <p><a href="mailto:1728209643@qq.com">XiaoSan</a>
 * @date 2019/9/3 10:16 AM
 */
public class LC_173 {

    static class BSTIterator {
        Stack<Integer> stack;
        public BSTIterator(TreeNode root) {
            stack = new Stack<>();
            build(root);
        }

        private void build(TreeNode root) {
            if (root != null) {
                build(root.right);
                stack.push(root.val);
                build(root.left);
            }
        }

        /** @return the next smallest number */
        public int next() {
            return stack.pop();
        }

        /** @return whether we have a next smallest number */
        public boolean hasNext() {
            return !stack.empty();
        }
    }

    static class TreeNode {

        int val;

        TreeNode left;

        TreeNode right;

        public TreeNode(int val) {
            this.val = val;
        }
    }

}
